package com.ideaction.entity.mail.filter;

import com.ideaction.entity.mail.BaseMail;
import com.ideaction.entity.mail.SysMail;
import com.ideaction.entity.mail.UserMail;

import java.util.List;
import java.util.Map;

/**
 * 平台渠道判断
 *
 * @author ZGame
 */
public class ChannelVersionFilter extends MailFilter {
    
    @Override
    protected boolean filtJudge(BaseMail mail, Map<String, Integer> sysMailStatus, String... params) {
        if (mail instanceof UserMail) {
            // 个人邮件直接过
            return false;
        } else {
            // 优先包含
            SysMail sysMail = (SysMail) mail;
            List<String> includeList = sysMail.getIncludeChannel();
            List<String> includeVersion = sysMail.getIncludeVersion();
            String channel = params[0];
            String version = params[1];
            // 非空进入判断
            if (!includeList.isEmpty()) {
                // 如果列表里面都没有该channel,后面就不用看了,直接过滤
                if (!includeList.contains(channel)) {
                    return true;
                }
                // 如果有,在去看版本列表里面有没有对包含对应版本,如果没有有则过滤
                if (!includeVersion.isEmpty()) {
                    if (!includeVersion.contains(version)) {
                        return true;
                    }
                }
            }
            // 如果includeList为空了,则只对includeVersion进行检查
            if (!includeVersion.isEmpty()) {
                if (!includeVersion.contains(version)) {
                    return true;
                }
            }
            
            // 排除
            List<String> excludeChannel = sysMail.getExcludeChannel();
            List<String> excludeVersion = sysMail.getExcludeVersion();
            if (!excludeChannel.isEmpty()) {
                //先看渠道排除列表是否包含
                if (excludeChannel.contains(channel)) {
                    //渠道排除列表有,则看版本排除,如果两者都包含了排除,则过滤
                    if (excludeVersion.isEmpty() || excludeVersion.contains(version)) {
                        return true;
                    }
                }
            }
            if (!excludeVersion.isEmpty()) {
                if (excludeVersion.contains(version)) {
                    return true;
                }
            }
            return false;
        }
        
    }
    
    public static void main(String[] args) {
        System.out.println(false | true);
    }
}
